package YuanShen;

import java.awt.*;
import java.util.*;

public class Chou {
    static String pool_five[] = {"迪卢克", "温迪", "公子", "钟离", "阿贝多", "魈"};
    static String pool_four[] = {"托马", "班尼特", "安柏", "香菱", "辛焱"};
    static String pool_up[] = {"胡桃"};
    static int num_double[] = {2, 2, 2, 2, 2, 2};
    static Map<String, Integer> five_role = new HashMap<>();
    static Map<String, Integer> four_role = new HashMap<>();


    private int baodi_five = 1;
    private int baodi_four = 1;
    private int baodi_up = 1;
    private int count_five;
    private int count_four;
    private int choujiangquan;
    private int yuanshi;
    private String name;

    Scanner scanner = new Scanner(System.in);

    public Chou(String name) {
        this.name = name;
        this.baodi_five = 1;
        this.baodi_four = 1;
        this.baodi_up = 1;
    }

    //游戏启动
    public void Menu() {
        System.out.println("原神启动！");
        while (true) {

            System.out.println("1、充值  2、抽卡 3、兑换 4、查看抽到的角色 5、退出 ");
            System.out.println("请输入以下操作：");
            switch (scanner.nextInt()) {
                case 1:
                    chongzhi();
                    break;
                case 2:
                    this.chouka();
                    break;
                case 3:
                    duihuan();
                    break;
                case 4:
                    select_role();
                    break;
                case 5:
                    ;
                default:
                    return;
            }
        }


    }

    //查看抽到的角色
    public void select_role() {
        System.out.print("五星角色：");
        for (Map.Entry<String, Integer> entry : five_role.entrySet()) {
            System.out.print(entry.getKey() + " " + entry.getValue() + "张，");
        }
        System.out.println();
        System.out.print("四星角色：");
        for (Map.Entry<String, Integer> entry : four_role.entrySet()) {
            System.out.print(entry.getKey() + " " + entry.getValue() + "张，");
        }
        System.out.println();
        System.out.println();
    }

    //充值
    public void chongzhi() {
        System.out.println("请输入您要充值的金额:");
        System.out.println("1：6元;2：30元;3:68元;4:128元;5:328元;6:648元;7:退出");
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt();
        switch (c) {
            case 1:
                this.yuanshi += (6 * 10 * this.num_double[c - 1]);
                System.out.printf("充值成功,原石剩余%d%n", this.yuanshi);
                Arrays.fill(this.num_double, 1);
                break;
            case 2:
                this.yuanshi += (30 * 10 * this.num_double[c - 1]);
                System.out.printf("充值成功,原石剩余%d%n", this.yuanshi);
                Arrays.fill(this.num_double, 1);
                break;
            case 3:
                this.yuanshi += (68 * 10 * this.num_double[c - 1]);
                System.out.printf("充值成功,原石剩余%d%n", this.yuanshi);
                Arrays.fill(this.num_double, 1);
                break;
            case 4:
                this.yuanshi += (128 * 10 * this.num_double[c - 1]);
                System.out.printf("充值成功,原石剩余%d%n", this.yuanshi);
                Arrays.fill(this.num_double, 1);
                break;
            case 5:
                this.yuanshi += (328 * 10 * this.num_double[c - 1]);
                System.out.printf("充值成功,原石剩余%d%n", this.yuanshi);
                Arrays.fill(this.num_double, 1);
                break;
            case 6:
                this.yuanshi += (648 * 10 * this.num_double[c - 1]);
                System.out.printf("充值成功,原石剩余%d%n", this.yuanshi);
                Arrays.fill(this.num_double, 1);
                break;
            case 7:
                ;
            default:
                return;
        }
    }

    //兑换
    public void duihuan() {//160个原石兑换1张券。
        if (yuanshi < 160) {
            System.out.println("当前原石的数量不足以兑换！");
            return;
        }
        System.out.printf("当前原石的数量为%d个，可以兑换到的券的数量为%d张 %n", yuanshi, yuanshi / 160);
        System.out.println();
        System.out.println("请输入您想要兑换到的券的数量：");
        int n = scanner.nextInt();
        if (this.yuanshi >= n * 160) {
            this.choujiangquan += n;
            this.yuanshi -= (n * 160);
            System.out.printf("兑换成功，您的原石数量剩余%d,抽奖券数量剩余%d%n", this.yuanshi, this.choujiangquan);
        } else {
            System.out.println("原石不足!剩余" + this.yuanshi + "个，请充值！");
        }
    }

    //抽卡
    public void chouka() {
        System.out.println("1、单抽 2、十连抽：");
        int choice = scanner.nextInt();
        int n = 0;
        if (choice == 1) {
            n = 1;
        } else if (choice == 2) {
            n = 10;
        } else {
            return;
        }
        //判断券的数量是否足够
        if (choujiangquan >= n) {
            for (int i = 0; i < n; i++) {
                if (this.baodi_five == 90) {
                    this.give_five();
                } else if (this.baodi_four == 10) {
                    this.give_four();
                } else {
                    int chouka = (int) (Math.random() * 1000);
                    //73  74:6.6%  75:12.6%
                    //从74抽开始，抽到五星的概率每次增加6%
                    if (chouka <
                            (this.baodi_five < 74 ? 6 : ((this.baodi_five - 73) * 60 + 6))) {
                        this.give_five();
                    } else if (chouka > 939) {
                        this.give_four();
                    } else {
                        System.out.println(this.name + "没有抽到角色");
                        this.baodi_five++;
                        this.baodi_four++;
                    }

                }
            }
            choujiangquan -= n;
        } else {
            System.out.println("抽奖券的数量不足，还需" + (n - choujiangquan) + "张，请充值");

        }

    }


    public void give_up() {
        this.baodi_five = 1;
        this.count_five++;
        this.baodi_four = 1;
    }

    public void give_five() {
        if (this.baodi_up == 2) {
            this.give_up();
        } else {
            int n = (int) (Math.random() * 2);
            if (n == 0) {
                this.give_up();
            } else {
                int five = (int) (Math.random() * pool_five.length);
                System.out.println(this.name + "抽到了五星***角色:" + pool_five[five]);
                this.baodi_five = 1;
                this.count_five++;
                this.baodi_up = 1;
                //将抽到的角色放到集合中

                if (five_role.containsKey(pool_five[five])) {
                    for (String key : five_role.keySet()) {
                        if (key.equals(pool_five[five])) {
                            int count = five_role.get(key);
                            five_role.put(pool_five[five], ++count);
                        }

                    }

                } else {
                    //如果集合中没有这个角色，就作为第一次添加进去
                    five_role.put(pool_five[five], 1);
                }


            }
        }
    }

    public void give_four() {
        int four = (int) (Math.random() * pool_four.length);
        System.out.println(this.name + "抽到了四星***角色:" + pool_four[four]);
        this.count_five++;
        this.baodi_four = 1;
        this.count_four++;
        if (four_role.containsKey(pool_four[four])) {
            for (String key : four_role.keySet()) {
                if (key.equals(pool_four[four])) {
                    int count = four_role.get(key);
                    four_role.put(pool_four[four], ++count);
                }

            }

        } else {
            //如果集合中没有这个角色，就作为第一次添加进去
            four_role.put(pool_four[four], 1);
        }
    }


}
